import 'package:boss/ui/page/commodity/categories/page/plusCommodityMode/page/plusPackage/widget/package_panel.dart';
import 'package:boss/ui/page/takeoutManagement/page/deliveryFeeSetting/provider/delivery_provider.dart';
import 'package:boss/ui/widget/form/base_text_form_field.dart';

import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';

class DeliveryFreePanel extends StatelessWidget {
  const DeliveryFreePanel({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return PackagePanel(
      title: '满额免配送费',
      headerPadding: EdgeInsets.zero,
      children: <Widget>[
        Consumer<DeliveryProvider>(
          builder: (context, provider, _) => BaseTextFormField(
            initialValue: AmountUtil.price2String(provider.data.freeDeliveryAmount),
            prefixText: '实付金额满',
            suffixText: '元，免费配送',
            hintText: '请输入',
            textAlign: TextAlign.center,
            keyboardType: TextInputType.numberWithOptions(decimal: true),
            inputFormatters: [FilteringTextInputFormatter.allow(RegUtil.numberReg)],
            onChanged: (value) {
              provider.data.freeDeliveryAmount = AmountUtil.string2Price(value);
            },
            maxLength: 9,
          ),
        ),
      ],
    );
  }
}
